package payroll.trans;

import payroll.Employee;
import payroll.PaymentClassification;
import payroll.PayrollDatabase;
import payroll.Transaction;
import payroll.classification.HourlyClassification;
import payroll.classification.TimeCard;
import payroll.exception.NoSuchEmployeeException;
import payroll.exception.NotHourlyClassificationException;

public class TimeCardTransaction implements Transaction {

    private int empId;
    private String date;
    private double hours; 

    public TimeCardTransaction(int empId, String date, double hours) {
        this.empId = empId;
        this.date = date;
        this.hours = hours;
    }

    @Override
    public void execute() {
        //how 添加时间卡？ 找到雇员，即 取雇员 [根据雇员编号 取雇员对象]
        Employee e= PayrollDatabase.getEmployee(empId);
        if(e == null)
            throw new NoSuchEmployeeException();
        // else          
        //取计算工资方式
        PaymentClassification pc = e.getPaymentClassification();
            if(pc instanceof HourlyClassification) {
            HourlyClassification hc = (HourlyClassification) pc;
            //添加时间卡 
            TimeCard tc = new TimeCard(date, hours);
            hc.addTimeCard(tc);
        }else {
            throw new NotHourlyClassificationException();
        }
    }
}
